package cn.corffen.test.algorithm.design;

import com.corffen.libsource.LinkedQueue;

import java.util.LinkedList;

public class FirstAppear {
    int[] chs = new int[256];
    LinkedList<Character> queue = new LinkedList<>();

    //Insert one char from stringstream
    public void Insert(char ch) {
        chs[ch]++;
        queue.add(ch);
        while (!queue.isEmpty() && chs[queue.peek()] > 1) {
            queue.poll();
        }
    }

    //return the first appearence once char in current stringstream
    public char FirstAppearingOnce() {
        return queue.isEmpty() ? '#' : queue.peek();
    }
}
